package org.example.studentsystem_back.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jakarta.annotation.Resource;
import org.example.studentsystem_back.common.CommonResponse;
import org.example.studentsystem_back.dto.PageDTO;
import org.example.studentsystem_back.service.NotificationsService;
import org.example.studentsystem_back.vo.notificitionsVo.NoVo;
import org.example.studentsystem_back.vo.notificitionsVo.NotificationsVo;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.text.ParseException;

@RestController
@Valid
public class NotificationsController {
    @Resource
    NotificationsService notificationsService;

    @PostMapping("/notifications/xntz")
    public CommonResponse<NotificationsVo> getNotifications1(@Valid @RequestBody PageDTO pageDTO) {
        return notificationsService.getAllNotifications("校内通知",pageDTO);
    }

    @PostMapping("/notifications/xxlh")
    public CommonResponse<NotificationsVo> getNotifications2(@Valid @RequestBody PageDTO pageDTO) {
        return notificationsService.getAllNotifications("学校例会",pageDTO);
    }

    @PostMapping("/notifications/xxgw")
    public CommonResponse<NotificationsVo> getNotifications3(@Valid @RequestBody PageDTO pageDTO) {
        return notificationsService.getAllNotifications("学校公文",pageDTO);
    }

    @PostMapping("/notifications/xxxx")
    public CommonResponse<NotificationsVo> getNotifications4(@Valid @RequestBody PageDTO pageDTO) {
        return notificationsService.getAllNotifications("学校信息",pageDTO);
    }

    @PostMapping("/notifications/xxgw/search")
    public CommonResponse<NotificationsVo> getNotifications5(@RequestBody String  json) throws ParseException {
        JSONObject jsonObject = JSON.parseObject(json);
        NoVo noVo=jsonObject.toJavaObject(NoVo.class);
        PageDTO pageDTO=jsonObject.toJavaObject(PageDTO.class);
        return notificationsService.getNotificationsSearch(noVo.getTitle(),noVo.getDepartment(),noVo.getDate1(),noVo.getDate2(),"学校公文",pageDTO);
    }

    @PostMapping("/notifications/xxlh/search")
    public CommonResponse<NotificationsVo> getNotifications6(@RequestBody String  json) throws ParseException {
        JSONObject jsonObject = JSON.parseObject(json);
        NoVo noVo=jsonObject.toJavaObject(NoVo.class);
        PageDTO pageDTO=jsonObject.toJavaObject(PageDTO.class);
        return notificationsService.getNotificationsSearch(noVo.getTitle(),noVo.getDepartment(),noVo.getDate1(),noVo.getDate2(),"学校例会",pageDTO);
    }

    @PostMapping("/notifications/xntz/search")
    public CommonResponse<NotificationsVo> getNotifications7(@RequestBody String  json) throws ParseException {
        JSONObject jsonObject = JSON.parseObject(json);
        NoVo noVo=jsonObject.toJavaObject(NoVo.class);
        PageDTO pageDTO=jsonObject.toJavaObject(PageDTO.class);
        return notificationsService.getNotificationsSearch(noVo.getTitle(),noVo.getDepartment(),noVo.getDate1(),noVo.getDate2(),"校内通知",pageDTO);
    }

    @PostMapping("/notifications/xxxx/search")
    public CommonResponse<NotificationsVo> getNotifications8(@RequestBody String  json) throws ParseException {
        JSONObject jsonObject = JSON.parseObject(json);
        NoVo noVo=jsonObject.toJavaObject(NoVo.class);
        PageDTO pageDTO=jsonObject.toJavaObject(PageDTO.class);
        return notificationsService.getNotificationsSearch(noVo.getTitle(),noVo.getDepartment(),noVo.getDate1(),noVo.getDate2(),"学校信息",pageDTO);
    }
}
